package org.dreamfly.core.action;

import org.dreamfly.core.bean.SzActivity;
import org.dreamfly.core.page.PageResultSet;
import org.dreamfly.core.service.ActivityService;

import java.util.List;

public class ActivityAction extends BaseAction {
    private PageResultSet<SzActivity> resultSet;
    private SzActivity activity;
    private SzActivity object;
    private ActivityService activityService;
    private String title;
    private Long id;
    private List<Long> deleteIds;
    private String server;
    private String note;
    private String minPicUrl;
    private String isAdmin;
    private String actionName;
    /**
     * 分页参数
     * pageSize 每页的大小
     * page     显示的页码
     */
    private Long pageSize = 5L;
    private Long page = 1L;

    /**
     * 按关键字搜索动作库
     *
     * @return success
     */
    public String searchActivity() {

        if (activity == null) {
            activity = new SzActivity();
            activity.setTitle("%");
        }
        if ("".equals(activity.getTitle())){
            activity.setTitle("%");
        }
        /*try {
            activity.setTitle(new String(activity.getTitle().getBytes("ISO-8859-1"),"UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.

        }*/
        if(isAdmin==null){
        	resultSet = activityService.normalSearch(activity, pageSize, page, null);
            resultSet.setActionName("activityNameSearch");
        }else{
        	resultSet = activityService.normalSearch(activity, 15l, page, server);
            resultSet.setActionName("bgActivity");
        }
        resultSet.setType("Activity");
        if (resultSet.getList() == null) {
            return INPUT;
        }
        resultSet.setKeyWords(activity.getTitle());


        return SUCCESS;
    }

    /**
     * 添加动作库信息
     *
     * @return
     */
    public String addActivityInfo() {
        SzActivity act = new SzActivity();
        act.setId(id);
        act.setTitle(title);
        act.setServer(server);
        act.setNote(note);
        act.setMinPictureUrl(minPicUrl);
        activityService.addActionInfo(act);
        return SUCCESS;
    }

    /**
     * 修改动作库
     *
     * @return
     */
    public String modifyActivity() {
        SzActivity act = new SzActivity();
        act.setId(id);
        act.setTitle(title);
        act.setServer(server);
        act.setNote(note);
        activityService.modifyActionInfo(act);
        return SUCCESS;
    }


    /**
     * 删除动作库
     *
     * @return
     */
    public String deleteActivity() {
        activityService.delete(id);
        return SUCCESS;
    }

    public String deleteActivityList(){
        for(Long id : deleteIds){
            activityService.delete(id);
        }
        return SUCCESS;
    }
    public String actionDetail(){
        object = activityService.findDetail(id);
        return null != object ? SUCCESS: INPUT;
    }

    public String getActionInfo(){
        object = activityService.findDetail(id);
        actionName = "modifyActivity";
        return null != object ?SUCCESS :INPUT;
    }
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getServer() {
        return server;
    }

    public void setServer(String server) {
        this.server = server;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public void setDeleteIds(List<Long> deleteIds) {
        this.deleteIds = deleteIds;
    }

    public void setAdmin(String admin) {
        isAdmin = admin;
    }

    public String getMinPicUrl() {
        return minPicUrl;
    }

    public void setMinPicUrl(String minPicUrl) {
        this.minPicUrl = minPicUrl;
    }

    public PageResultSet<SzActivity> getResultSet() {
        return resultSet;
    }

    public void setResultSet(PageResultSet<SzActivity> resultSet) {
        this.resultSet = resultSet;
    }

    public SzActivity getActivity() {
        return activity;
    }

    public void setActivity(SzActivity activity) {
        this.activity = activity;
    }

    public ActivityService getActivityService() {
        return activityService;
    }

    public void setActivityService(ActivityService activityService) {
        this.activityService = activityService;
    }

    public Long getPageSize() {
        return pageSize;
    }

    public void setPageSize(Long pageSize) {
        this.pageSize = pageSize;
    }

    public Long getPage() {
        return page;
    }

    public void setPage(Long page) {
		this.page = page;
	}

	public String getIsAdmin() {
		return isAdmin;
	}

	public void setIsAdmin(String isAdmin) {
		this.isAdmin = isAdmin;
	}

    public SzActivity getObject() {
        return object;
    }

    public String getActionName() {
        return actionName;
    }
}
